import { defineStore } from 'pinia';
import { IRouter } from '@/router/type';

interface IPermission {
    routes: Array<IRouter>;
    homeRoute: IRouter;
    permissions: Array<string>;
    flatRoutes: Array<IRouter>;
    sideRoutes: Array<IRouter>;
    menuRoutes: Array<IRouter>;
}

const permissionStore = defineStore({
    id: 'permission',
    state: (): IPermission => ({
        routes: [],//用户路由权限
        homeRoute: {
            path: '',
            redirect:''
        },//第一个页面地址信息
        permissions: [],//用户按钮级权限
        flatRoutes: [],//打平路由
        sideRoutes: [],//顶部菜单布局时侧面菜单内容
        menuRoutes: [],//顶部菜单布局时侧面菜单内容
    }),
    actions: {
        //更新路由
        updateRoutes(routes: any): void {
            this.routes = routes;
            if (routes.length) {
                let firstItem = routes[0];
                this.homeRoute = firstItem;
            }
        },
        //更新按钮权限
        updateBtnPermissions(permissions: Array<string>): void {
            this.permissions = permissions
        },
        //跟新侧面一级菜单
        updateSideRoutes(sideRoutes: Array<IRouter>): void {
            this.sideRoutes = sideRoutes;
        }
    }
});

export default permissionStore;